package lab03.test14;

import java.sql.*;

public class Test14 {
    public static void main(String[] args) {


        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;

        String insert ="insert INTO "
                + "userinfo(usercode,username,password,email)"
                +"values ('7106','曲小声','654321','xiaosheng@263.net')";

        String select = "select * from userinfo";

        try {
            Class.forName("com.mysql.jdbc.Driver");

            connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC",
                    "root",
                    "123456"
            );


            statement = connection.createStatement();
            resultSet = statement.executeQuery(select);

            while (resultSet.next()){
                System.out.print(resultSet.getString("usercode")+"  ");
                System.out.print(resultSet.getString("username")+"  ");
                System.out.print(resultSet.getString("password")+"  ");
                System.out.println(resultSet.getString("email")+"   ");
            }

            statement.execute(insert);
            resultSet = statement.executeQuery(select);

            while (resultSet.next()){
                System.out.print(resultSet.getString("usercode")+"  ");
                System.out.print(resultSet.getString("username")+"  ");
                System.out.print(resultSet.getString("password")+"  ");
                System.out.println(resultSet.getString("email")+"   ");
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

